
import 'package:flutter/material.dart';
import 'package:flutter_class2/common/global.dart';

import 'accountRelated/account_controller.dart';


class PersonPage extends StatelessWidget {
  Widget build(BuildContext context){
    return PersonPageState();
  }
}

class PersonPageState extends StatefulWidget {
  @override
  _PersonPageState createState() => new _PersonPageState();
}

class _PersonPageState extends State<PersonPageState>{

  var databaseHelper = new AccountDatabaseHelper();
  var account;
  var phoneNumStr;
  var emailStr;

  @override
  Widget build(BuildContext context) {
    getAccount();

    final headPic = Hero(// 创建hero动画，沟通两个组件之间的tag必须统一
      tag: 'personHeadPic',
      child: CircleAvatar(
        backgroundColor: Colors.transparent,
        radius: 48.0,
        child: ClipRRect(
          borderRadius: BorderRadius.all(Radius.circular(90)),
          child: Image.asset('images/meng.png'),
        ),
      ),
    );

    final id = Container(
      child: Text(
        Global.currentId,
        maxLines: 1,
        overflow: TextOverflow.ellipsis,
        style: TextStyle(fontSize: 18 ,fontWeight: FontWeight.bold),
      ),
    );

    final phoneNum = Container(
      padding: EdgeInsets.only(top: 10),
      child: Text("手机：" + Global.currentPhoneNum),
    );

    final email = Container(
      padding: EdgeInsets.only(top: 10),
      child: Text("邮箱：" + Global.currentEmail),
    );

    final changeAccountBtn = RaisedButton(
      child: Row(
        children: [
          Icon(Icons.edit_outlined),
          Text(" 编辑"),
        ],
      ),
      color: Colors.transparent,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(16),
      ),
      onPressed: (){
        Navigator.pushNamed(context, '/changeAccount')
            .then((value) => value?_getRequests():null);//通过then来监听回调并刷新页面（刷新功能暂时无效）
      },
    );

    return Scaffold(
      resizeToAvoidBottomInset: false,// 防止弹出输入法时内容溢出屏幕
      body: Container(
        padding: EdgeInsets.all(20.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    crossAxisAlignment: CrossAxisAlignment.end,
                    children: [
                      headPic,
                      id,
                    ]
                ),
                changeAccountBtn,
              ],
            ),
            SizedBox(height: 20,),
            Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                phoneNum,
                email,
              ],
            ),
          ],
        ),
      ),
    );
  }

  _getRequests()async{
    print('此时进行了监听回调和页面刷新的操作');// 此时进行了监听回调和页面刷新的操作（刷新功能暂时无效）
  }

  getAccount() async{
    account = await databaseHelper.getAccount(Global.currentId);
    print("PersonPage=> " + account.nickName);
  }

}
